print(type('Hello World'))
# <class 'str'>
print(type('早安你好'))
# <class 'str'>
print(type('123456'))
# <class 'str'>
print(type('True'))
# <class 'str'>
字串串接
用法:字串1 + 字串2
print('Hello World' + ' ' + ' Happy coding!')
# Hello World Happy coding!
用法:字串 * 次數
a = 'Good! '
print(a * 3)
# Good! Good! Good!
a = 'Good! '
print(a * 3)
# Good! Good! Good!
print(a * 3.0)
# TypeError: can't multiply sequence by non-int of type 'float'
用法:len(字串)
a = '123'
b = '456789!'
print(len(a))
# 3
print(len(b))
# 7
print(len(a+b))
# 10
用法:字串[起始位置:結束位置:間隔值]
a = '123'
b = '456789!'
print(len(a))
# 3
print(len(b))
# 7
print(len(a+b))
# 10
a = 'Hello'
print(a[-5:-2])
# Hel
print(a[0:-2])
# Hel
print(a[-5:3])
# Hel
print(a[0:3])
# Hel
a = 'Hello'
print(a[1:])
# ello
print(a[-4:])
# ello
print(a[:])
# Hello
a = 'Hello'
print(a[1:])
# ello
print(a[-4:])
# ello
print(a[:])
# Hello